<?php
/**
 * Created by PhpStorm.
 * User: czm
 * Date: 2019-07-17
 * Time: 17:27
 */
namespace app\index\controller;

use think\Controller;
use think\Db;
use think\Session;

class Business extends Controller
{
    // 商家管理
    public function businessList()
    {
        $dat = input('phone');
        $list = Db::name('business')->where('phone',$dat)->find();
        $a = $list['state'];
        if($list){
            $data = ['code' => 436, 'msg' => '不是商家'];
            return json_encode($data,TRUE);
        }
        if ($a == 0){
            $data = ['code' => 437, 'msg' => '未被审核'];
            return json_encode($data,TRUE);
        }
        if(Db::name('business')->where('phone',$dat)->find()){
            $da = ['code' => 200, 'msg' => 'OK'];
            return json_encode($da);
        }else{
            $da = ['code' => 403, 'msg' => '失败'];
            return json_encode($da,TRUE);
        }

    }

    // 商家入驻
    public function businessAdd()
    {
        $da = input('post.');
        $a = $da['id'];
        $b = $da['name'];
        $data = ['uid' => $a];
        if (request()->isPost())
        {

            $data = input('post.');

            $data =[
                'vip_type' => $a,
            ];
            if ($_FILES['pic']['tmp_name'])
            {
                $file=request()->file('pic');//文件上传
                $info = $file->validate(['size'=>2567800])->move(ROOT_PATH . 'public' . DS . 'static/images');//移动文件，DS代表/或者\斜杠
                $data['pic']=$info->getSaveName();//图片的保存路径
            }
            if ($_FILES['pic']['size'] > 2567800)
            {
                $dat = ['code' => 402, 'msg' => '图片超过2M'];
                return json_encode($dat, TRUE);
            }
            if (Db::name('business')->insert($data)){
                $dat = ['code'=> 200, 'msg' => '成功'];
                return json_encode($dat);
            }else{
                $dat = ['code' => 403, 'msg' => '失败'];
                return json_encode($dat,TRUE);
            }
        }
    }


}